using System;
using System.Collections;
using NUnit.Framework;
using NPlot.Bitmap;

using Evaluant.Uss;

namespace NUnit.Performances.Engines
{
	[TestFixture]
	public class PerformanceTester
	{
		Hashtable _PersistenceEngines = new Hashtable();
		private int _Widht = 500, _Height = 500;

		public PerformanceTester()
		{
			IPersistenceProvider pf ;

			pf = XmlConfigLoader.LoadXmlConfig(@"engines.config", "Xml");
			pf.RegisterMetaData(MetaDataFactory.FromMetaDataFile(@"..\..\PersistenceEngine\Models\Person.xml"));
			_PersistenceEngines.Add("Xml", pf.CreatePersistenceEngine());

//			pf = XmlConfigLoader.LoadXmlConfig(@"engines.config", "Sql");
//			pf.RegisterMetaData(MetaDataFactory.FromMetaDataFile(@"..\..\PersistenceEngine\Models\Person.xml"));
//			_PersistenceEngines.Add("Sql", pf.CreatePersistenceEngine());

			pf = XmlConfigLoader.LoadXmlConfig(@"engines.config", "SqlServerSpecific");
			pf.RegisterMetaData(MetaDataFactory.FromMetaDataFile(@"..\..\PersistenceEngine\Models\Person.xml"));
			_PersistenceEngines.Add("SqlMapper", pf.CreatePersistenceEngine());

		}

		private System.Drawing.Color[] _Colors = new System.Drawing.Color[] { System.Drawing.Color.Blue, System.Drawing.Color.Red, System.Drawing.Color.Purple, System.Drawing.Color.Indigo, System.Drawing.Color.GreenYellow };

		private void ProcessTest(ITest tester)
		{
		}

		[Test]
		public void PersistenceEngineWrite()
		{
			PlotSurface2D surface = new PlotSurface2D(_Widht, _Height);
			PersistenEngineWrite tester = new PersistenEngineWrite();

			IEnumerator colors = _Colors.GetEnumerator();

			foreach(DictionaryEntry de in _PersistenceEngines)
			{
				IPersistenceEngine pe = de.Value as IPersistenceEngine;
				pe.InitializeRepository();
				colors.MoveNext();
				tester.PersistenceEngine = pe;

				NPlot.LinePlot plot = new NPlot.LinePlot();
				plot.Label = de.Key.ToString();

				plot.Color = (System.Drawing.Color)colors.Current;
				plot.DataSource = tester.Launch();
				surface.Add(plot);
			}

			NPlot.Legend legend = new NPlot.Legend();
			legend.AttachTo( NPlot.PlotSurface2D.XAxisPosition.Top, NPlot.PlotSurface2D.YAxisPosition.Left );
			legend.VerticalEdgePlacement = NPlot.Legend.Placement.Inside;
			legend.HorizontalEdgePlacement = NPlot.Legend.Placement.Inside;
			legend.YOffset = 8;

			surface.Legend = legend;
			surface.LegendZOrder = 1; // default zorder for adding idrawables is 0, so this puts legend on top.

			surface.BackColor = System.Drawing.Color.White;
			tester.SetAxis(surface);

			surface.Title = "Write";
			surface.Refresh();

			surface.Bitmap.Save("c:\\test.png", System.Drawing.Imaging.ImageFormat.Png);
		}
	}
}
